//
//  PeriodsViewController.m
//  消费100
//
//  Created by eliot on 16/3/31.
//  Copyright © 2016年 aleven. All rights reserved.
//

#import "PeriodsViewController.h"
#import "GetResultsTableViewController.h"


@interface PeriodsViewController ()

/** 数据源 有多少期*/
@property (nonatomic, strong) NSArray *periodsArr;



@end

@implementation PeriodsViewController

+(PeriodsViewController*)CreatPeriodsViewController{
    
    UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    PeriodsViewController *PeriodsViewController=[story instantiateViewControllerWithIdentifier:@"PeriodsViewController"];
    return PeriodsViewController;
}

- (NSArray *)periodsArr {
    if (!_periodsArr) {
        _periodsArr = @[@"第一期",
                        @"第二期",
                        @"第三期",
                        @"第四期"];
    }
    return _periodsArr;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self showPerioidsView];
    self.title = @"选择期数";
    self.view.backgroundColor = [UIColor colorWithRed:232/255.0 green:233/255.0 blue:232/255.0 alpha:1];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    self.navigationController.navigationBar.translucent = NO;
    
}

- (void)showPerioidsView{

    for (int i = 0; i < self.periodsArr.count; i ++) {
        NSLog(@"%d", i);
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.tag = i;
        [self.view addSubview:btn];
        [btn setTitle:self.periodsArr[self.periodsArr.count - 1 - i] forState:UIControlStateNormal];
        btn.layer.cornerRadius = 6;
        btn.layer.masksToBounds = YES;
        [btn addTarget:self action:@selector(clickAmountOfChargeBtn:) forControlEvents:UIControlEventTouchUpInside];
        btn.backgroundColor =  [UIColor whiteColor];
        btn.titleLabel.font = [UIFont systemFontOfSize:14];
        if (i == 0) {
            [btn setTitleColor:[UIColor colorWithRed:254/255.0 green:154/255.0 blue:37/255.0 alpha:1] forState:UIControlStateNormal];
        }else {
            [btn setTitleColor: [UIColor colorWithRed:82/255.0 green:82/255.0 blue:82/255.0 alpha:1] forState:UIControlStateNormal];
        }
        
        
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo((Width - 3) / 3.0 / 2.6);
            make.width.mas_equalTo((Width - 3) / 3.0);
            if (i % 3 == 0) {
                make.left.mas_equalTo(0);
                if (i / 3 == 0) {
                    make.top.mas_equalTo(0);
                }else {
                    make.top.mas_equalTo(((Width - 3) / 3.0 / 2.6 + 10)* i/3);
                }
            }
            if (i % 3 == 1) {
                make.left.mas_equalTo((Width - 3) / 3.0 + 1);
                if (i / 3 == 0) {
                    make.top.mas_equalTo(0);
                }else {
                    make.top.mas_equalTo(((Width - 3) / 3.0 / 2.6 + 10)* i/3);
                }
            }
            if (i % 3 == 2) {
                make.left.mas_equalTo((Width - 3) / 3.0 *2 + 2);
                if (i / 3 == 0) {
                    make.top.mas_equalTo(0);
                }else {
                    make.top.mas_equalTo(((Width - 3) / 3.0 / 2.6 + 10)* i/3);
                }
            }
        }];
    }
}

/** 点击以往期数*/
- (void)clickAmountOfChargeBtn:(UIButton *)btn {

    GetResultsTableViewController *vc = [GetResultsTableViewController CreatGetResultsTableViewController];
    [self creatNav:vc];

}

//创建模态导航控制器
-(void)creatNav:(UIViewController *)view{
    
//    UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:view];
//    nav.navigationBar.barTintColor = [UIColor colorWithRed:254/255.0 green:154/255.0 blue:37/255.0 alpha:1];
    view.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back"] style:UIBarButtonItemStylePlain target:self action:@selector(dismiss)];
    [self.navigationController pushViewController:view animated:YES];
   // [self presentViewController:nav animated:YES completion:nil];
}

- (void)dismiss {
    [self.navigationController popViewControllerAnimated:YES];
    //[self dismissViewControllerAnimated:YES completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
